class Solution {
public:
    int ret = 0;
    bool check[20] = {false};
    void dfs(int n, int k) {
        if(k == n + 1){
            ret++;
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (check[i] == false && (k % i == 0 || i % k == 0)) {
                check[i] = true;
                dfs(n, k + 1);
                check[i] = false;
            }
        }
    }
    int countArrangement(int n) {
        dfs(n, 1);
        return ret;
    }
};